package com.tanhua.app.controllerservice;

import com.tanhua.api.mongo.PublishApi;
import com.tanhua.domain.mongo.Publish;
import com.tanhua.domain.vo.UserHolder;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class  QuanziMQService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Reference
    private PublishApi publishApi;

    public void snedMQ(String type, String publishId) {

        //将用户行为发送到mq
        Map map = new HashMap();
        map.put("userId", UserHolder.getUser().getId());
        map.put("type",type);

        Publish publish = publishApi.findById(publishId);
        map.put("pid",publish.getPid());

        rocketMQTemplate.convertAndSend("tanhua-bigdata",map);

        System.out.println("已经将用户行为发送到mq了.....");

    }
}
